<!--
 * @Author: cgl
 * @Date: 2023-04-18 15:12:26
 * @LastEditors: cgl
 * @LastEditTime: 2023-05-26 10:49:13
 * @FilePath: \public-health-emergencies-fed:\radiation-hygiene-fe\src\views\basicData\environment.vue
 * @Description:
 *
 * Copyright (c) 2023 by cgl/微盛信息产业有限公司, All Rights Reserved.
-->
<template>
  <div class="app-container">
    <el-form
      class="searchform"
      :model="queryParams"
      ref="queryParams"
      size="small"
      label-width="100px"
    >
      <el-row>
        <el-col :span="5">
          <el-form-item label="月份查询" label-width="80px">
            <el-date-picker
              v-model="queryParams.createTime"
              value-format="yyyy-MM"
              type="month"
              placeholder="选择月"
              clearable
              style="width: 100%"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item label-width="20px">
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="getList()"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="reset()"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div
      class="tableoperation"
      style="display: flex; justify-content: space-between"
    >
      <el-button
        type="primary"
        icon="el-icon-plus"
        style="margin-right: 10px"
        size="mini"
        @click.native.prevent="openDialog()"
        >添加</el-button
      >
      <print :disabled="environmentList.length == 0" title="环境条件">
        <table
          id="table"
          style="width: 100%"
          border="1"
          cellspacing="0"
          cellpadding="0"
          align="center"
        >
          <thead>
            <tr>
              <td rowspan="2" align="center">日期</td>
              <td colspan="4" align="center">上午</td>
              <td colspan="4" align="center">下午</td>
            </tr>
            <tr>
              <td align="center">温度（℃）</td>
              <td align="center">湿度（%RH）</td>
              <td align="center">记录时间</td>
              <td align="center">记录人</td>
              <td align="center">温度（℃）</td>
              <td align="center">湿度（%RH）</td>
              <td align="center">记录时间</td>
              <td align="center">记录人</td>
            </tr>
          </thead>
          <tr v-for="(item, index) in environmentList" :key="index">
            <td align="center">{{ item.createTime }}</td>
            <td align="center">{{ item.amTemperature }}</td>
            <td align="center">{{ item.amHumidity }}</td>
            <td align="center">{{ item.amCreateTime }}</td>
            <td align="center">{{ item.amCreateNickName }}</td>
            <td align="center">{{ item.pmTemperature }}</td>
            <td align="center">{{ item.pmHumidity }}</td>
            <td align="center">{{ item.pmCreateTime }}</td>
            <td align="center">{{ item.pmCreateNickName }}</td>
          </tr>
        </table>
      </print>
    </div>
    <el-table
      v-loading="loading"
      :data="environmentList"
      :height="height - 330 + 'px'"
    >
      <el-table-column label="日期" align="center" prop="createTime" />
      <el-table-column label="上午" align="center">
        <el-table-column
          label="温度（℃）"
          align="center"
          prop="amTemperature"
        />
        <el-table-column label="湿度（%RH）" align="center" prop="amHumidity" />
        <el-table-column label="记录时间" align="center" prop="amCreateTime" />
        <el-table-column
          label="记录人"
          align="center"
          prop="amCreateNickName"
        />
      </el-table-column>
      <el-table-column label="下午" align="center">
        <el-table-column
          label="温度（℃）"
          align="center"
          prop="pmTemperature"
        />
        <el-table-column label="湿度（%RH）" align="center" prop="pmHumidity" />
        <el-table-column label="记录时间" align="center" prop="pmCreateTime" />
        <el-table-column
          label="记录人"
          align="center"
          prop="pmCreateNickName"
        />
      </el-table-column>
    </el-table>

    <!-- 弹框 -->
    <el-dialog
      title="环境条件"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="550px"
      class="eviromentDialog"
      v-dialogDrag="true"
    >
      <el-form
        :model="form"
        :rules="rules"
        ref="form"
        size="small"
        label-width="100px"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="温度(℃)" prop="temperature">
              <el-input
                v-model="form.temperature"
                placeholder="请输入"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="湿度(%RH)" prop="humidity">
              <el-input
                v-model="form.humidity"
                placeholder="请输入"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  environmentList,
  environmentRecorders,
  environmentDetail,
  environmentAdd,
} from "@/api/basicData/environment";
import { areaList, areadeptTree, getInfoarea } from "@/api/area";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "environment",
  dicts: ["equipment_state"],
  components: { Treeselect },
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      dialogVisible: false,
      rules: {
        temperature: [
          { required: true, message: "温度不能为空", trigger: "blur" },
        ],
        humidity: [
          { required: true, message: "湿度不能为空", trigger: "blur" },
        ],
      },
      list: [
        { label: "1", value: "1" },
        { label: "2", value: "2" },
        { label: "3", value: "3" },
      ],
      // 视图高度
      height: document.documentElement.clientHeight,
      // 环境列表
      environmentList: [],
      // 表单参数
      form: {},
      loading: false,
      status: null,
      title: null,
      // 记录人下拉框
      recorderList: [],
    };
  },
  created() {
    this.reset();
    // this.getList();
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true;
      environmentList(this.queryParams)
        .then((response) => {
          this.environmentList = response.data;
          this.loading = false;
        })
        .catch((response) => {
          this.loading = false;
        });
    },
    // 打开对话框
    openDialog() {
      this.resetForm("form");
      this.form = {};
      this.dialogVisible = true;
    },
    // 提交按钮
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) return;
        environmentAdd(this.form).then((response) => {
          this.$modal.msgSuccess("保存成功");
          this.dialogVisible = false;
          this.getList();
        });
      });
    },
    // 表单重置
    reset() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        createTime: null,
      };
      this.resetForm("queryParams");
      let month = this.parseTime(new Date()).slice(0, 7);
      this.queryParams.createTime = month;
      this.getList();
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .pagination-container {
  margin-top: 70px;
}
.eviromentDialog ::v-deep .el-dialog__body .el-form {
  margin-left: -20px;
}
</style>
